#include<bits/stdc++.h>
#define sd(n) scanf("%d",&n) 
#define sld(n) scanf("%lld",&n)
#define pd(n) printf("%d", (n))
#define pld(n) printf("%lld", n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
const int N = 2e5;
#define INF 0x7fffffff
typedef long long int ll;
using namespace std;
//----------------------------------------------------------------------------//

void solve()
{
	int n;
	sd(n);
	string s;
	cin >> s;
	int rl=INF, lel=-1;
	int pos = 0;

	bool flag_l = false;
	bool flag_r = false;
	for (auto& k : s)
	{

		if (k == 'R') rl = pos, flag_r = true;
		else if (k == 'L') lel = pos, flag_l = true;
		pos++;
	}

	if (flag_r == true && flag_l == true && rl > lel)
	{
		for(int i=0;i<n-1;i++)
		{
			if(s[i]=='L'&&s[i+1]=='R')
			{
				pd(i+1);
				break;
			}
		}
		puts("");
		return;
	}

	if (rl < lel)
	{
		pd(0);
		puts("");
		return;
	}


	pd(-1);
	puts("");

}

int main()
{
	int T;
	sd(T);
	while (T--)
	{
		solve();
	}
	return 0;
}